#pragma once

#include <metalc/chksum/_chksum.h>

#define XORCHK(val, key)			(val ^ key)

#define DEF_XORCHK(name, chksum_type, key)	\
DECL_CHKSUM(name, chksum_type)			\
SAI size_t sizeofchksum_##name (){ return sizeof(chksum_type); }\
SAI bool_t data2chksum_##name (chksum_type##_chksum *dst, chksum_type *src, size_t sz_dst, size_t sz_src){\
	if (sz_dst < sz_src) return FALSE;\
	for (word_t idx = 0; idx < sz_dst/sizeof(sizeof(chksum_type)); idx++){\
		dst[idx] = XORCHK(src[idx], key);\
	}\
	return TRUE;}\
SAI bool_t chksum2data_##name (chksum_type *dst, chksum_type##_chksum *src, size_t sz_dst, size_t sz_src){\
	if (sz_dst < sz_src) return FALSE;\
	for (word_t idx = 0; idx < sz_dst/sizeof(sizeof(chksum_type##_chksum)); idx++){\
		dst[idx] = XORCHK(src[idx], key);\
	}\
	return TRUE;}

